package com.snda.setupmanager;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SimpleSqlLite {
	private static final String LOGTAG = "SimpleSqlLite";
	
	private String mDBName = null;
	private SQLiteDatabase mDBBase = null;

	private SimpleSqlLite(String pDBName){
		mDBName = pDBName;
	}
	
	public int Open(){
		mDBBase = SQLiteDatabase.openOrCreateDatabase(mDBName, null);

		if (mDBBase == null){
			Log.e(LOGTAG, "Open DB fail!");
		}
		
		return 0;
	}
	
	public void Close(){
		mDBBase.close();
	}
	
	public boolean IsTableExist(String pTbName){
		return true;
	}
	
	public boolean RunSql(String pSQL){
	    try {
	    	mDBBase.execSQL(pSQL);
	    } catch (SQLException e) {
	    	Log.e(LOGTAG, "execSQL is fail! sql=(" + pSQL + ") error=" + e.getMessage());
	    	return false;
	    }   
		return true;
	}
	
	public SQLiteDatabase GetDB(){
		if (mDBBase != null)
			return mDBBase;
		 
		return null;
	}
	
//	private class SimpleSQLiteOpenHelper extends SQLiteOpenHelper{
//		 public SimpleSQLiteOpenHelper(Context pContext, String pDBName, 
//				 CursorFactory pFactory, int pVersion) {
//			 super(pContext, pDBName, pFactory, pVersion);
//		 }
//
//		@Override
//		public void onCreate(SQLiteDatabase db) {
//			
//		}
//
//		@Override
//		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//			
//		}
//	}
}
